// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.tcmdb.util.validations;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import de.servicezombie.lang.Configuration;
import de.servicezombie.tcmdb.TcmdbValidationFailedException;
import de.servicezombie.tcmdb.util.TestExecutionUtils;

public class ValidateTestExecutionResolution implements Validation<String> {

	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	@Override
	public void validate(String resolution) throws TcmdbValidationFailedException {
		
		if(StringUtils.isBlank(resolution)) {
			throw new TcmdbValidationFailedException("resolution may not be blank");
		}
		
		String[] acceptedValues = TestExecutionUtils.getKnownResolutions(configuration);
		if(!ArrayUtils.contains(acceptedValues, resolution)) {
			throw new TcmdbValidationFailedException("resolution '" + resolution + "' is not known. It must one of " + ArrayUtils.toString(acceptedValues));
		}
	}

}
